<template>
  <div id="plan_all">
    <div class="search">
      <el-form :inline="true" :model="search" class="demo-form-inline">
        <el-form-item label="输入搜索">
          <el-input
            v-model="search.key"
            placeholder="请输入设备名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="输入时间">
          <el-date-picker
            v-model="search.time"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="chage"
          ></el-date-picker>
        </el-form-item>
        <el-form-item
        >
          <el-button type="primary" @click="onsubmit"
          >查询
          </el-button
          >
        </el-form-item
        >
      </el-form>
      <el-button class="ebtn" type="warning" @click="addorder()">新增计划</el-button>
    </div>
    <div class="order_table">
      <template>
        <el-table :data="ListData" style=" margin: 10px 20px;width: calc(100% - 40px)" :height="autoHeightTable" stripe>
          <el-table-column
            label="序号"
            align="center"
          >
            <template slot-scope="scope">
              <span>{{ scope.$index + 1 }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="clientName"
            label="客户"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="createonTime"
            label="创建时间"
            align="center"
          >
            <template v-slot="scope">
              <span>
                {{ formatTime(scope.row.createonTime) }}
              </span>
            </template>
          </el-table-column>
          <el-table-column
            prop="status"
            label="状态"
            align="center"
          >
            <template slot-scope="scope">
              <span v-if="scope.row.status==1">待审核</span>
              <span v-if="scope.row.status==2">已完成</span>
              <!--              <span v-if="scope.row.status==3">驳回</span>-->
              <el-button v-if="scope.row.status == 3" type="text" size="medium"
                         @click="dialogVisible_bohui = true,getReject(scope.row)">驳回
              </el-button>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" width="200">
            <el-row slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="xq(scope.row.id, 0)"
              >详情
              </el-button
              >
            </el-row>
          </el-table-column>
        </el-table>
      </template>
      <div class="block">
        <el-pagination
          background
          layout="prev, pager, next"
          :current-page="current"
          :page-size="pagesize"
          @current-change="handleCurrentChange"
          :page-count="total"
        >
        </el-pagination>
      </div>
    </div>
    <el-dialog
      title="驳回详情"
      :visible.sync="dialogVisible_bohui"
      width="50%"
      :modal-append-to-body="false">
      <ul :data="reject" class="bohuizujian">
        <li>
          <span>审核日期</span>
          <el-input v-model="reject.checkTime" style="width: 70%;" disabled></el-input>
        </li>
        <li>
          <span>驳回理由</span>
          <el-input v-model="reject.bohui" style="width: 70%;" disabled></el-input>
        </li>
      </ul>

      <span slot="footer" class="dialog-footer">
    <el-button type="primary" @click="dialogVisible_bohui = false">返 回</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>
import axios from "axios";

export default {
  data() {
    return {
      reject: {
        checkTime:"",
        bohui:"",
      },
      search: {key: "", start: "", end: ""},
      ListData: [],
      total: 1,
      current: 1,
      pagesize: 10,
      dialogVisible_bohui: false,
      bohuilist: {
        bohuiReason: "",
        checkTime: "",
        userName: "",
      },
    };
  },
  computed: {
    autoHeightTable() {
      return document.documentElement.scrollHeight - 251 - 78;
    },
  },
  created() {
    this.getList();
  },
  methods: {
    getReject(row) {
      this.reject = row
      this.reject.checkTime = this.formatTime(row.checkTime)
      console.log(this.formatTime(row.checkTime))
    },
    //时间格式化
    formatTime(data) {
      return data == null ? "" : data.substring(0, 10);
    },

    getList() {
      const json = {
        beginTime: this.search.start,
        endTime: this.search.end,
        key: this.search.key,
        pageNum: this.current,
        pageSize: this.pagesize,
      };
      const message = JSON.parse(localStorage.getItem("message"));
      axios
        .post(
          "/JX_java/sales/orderFrom/getSaleOrderPlanList?userId=" + message.Id,
          json
        )
        .then((res) => {
          this.ListData = res.data.data.content;
          console.log(this.ListData)
          this.total = res.data.data.totalPages
        });
    },
    handleCurrentChange(e) {
      this.current = e;
      this.getList();
    },

    onsubmit() {
      this.getList();
      // this.LoadContents();
    },

    chage(e) {
      if (e) {
        this.search.start = e[0];
        this.search.end = e[1];
      } else {
        this.search.start = "";
        this.search.end = "";
      }
    },
    // 分页
    handleCurrentChangeqq(e) {
      this.current = e
      this.getList();
    },
    //订单计划详情
    xq(id, e) {
      this.$router.push({
        path: "/SalesPlanXq",
        query: {id: id, e: e},
      });
    },
    //新增订单计划
    addorder() {
      this.$router.push("/SalesPlanAdd");
    },
  },
};
</script>

<style lang="scss" scoped>
@import "@/assets/scss/base.scss";

#plan_all .search {
  height: 50px;
  border-radius: 5px;
  background-color: #fff;
  padding-left: 20px;
  padding-top: 10px;
  // margin: 0 20px 20px;
  margin: 0 20px;
}

#plan_all .demo-form-inline {
  display: inline-block;
}

#plan_all .el-pagination {
  margin-top: 15px;
  text-align: center;
}

#plan_all .ebtn {
  float: right;
  margin-right: 20px;
}

.bohuizujian {
  display: flex;
  flex-wrap: wrap;

  li {
    width: 50%;
    padding-top: 10px;
    text-align: center;

    span {
      display: inline-block;
      width: 25%;
    }

  }
}
</style>
<style>
.el-dialog__footer {
  text-align: center;
}

#plan_all .el-dialog__body {
  padding-top: 0;
}


</style>
